using System;
using System.Collections.Generic;

[Serializable]
public class OwnedItemsAchievement : GameplayAchievement
{
	[Serializable]
	public class Stage
	{
		public string itemId;

		public string reward;
	}

	public const AchievementResource.AchievementType achievementType = AchievementResource.AchievementType.ItemAchievement;

	public List<Stage> eligibleItems = new List<Stage>();

	public override bool shouldShowAchievementStageCompleted
	{
		get
		{
			return model.stageReported < achievedStagesCount;
		}
	}

	public override int achievedStagesCount
	{
		get
		{
			int num = 0;
			foreach (Stage eligibleItem in eligibleItems)
			{
				StoreItemsConfig.StoreItem storeItem = StoreItemsConfig.instance.FindItemWithId(eligibleItem.itemId);
				if (storeItem.IsOwned())
				{
					num++;
				}
			}
			return num;
		}
	}

	public override int totalStages
	{
		get
		{
			return eligibleItems.Count;
		}
	}

	public override void OnShowAchievementStageCompleted(int achievedStageCount)
	{
		model.items.Clear();
		foreach (Stage eligibleItem in eligibleItems)
		{
			StoreItemsConfig.StoreItem storeItem = StoreItemsConfig.instance.FindItemWithId(eligibleItem.itemId);
			if (storeItem.IsOwned())
			{
				model.items.Add(storeItem.id);
			}
		}
		model.stageReported = achievedStageCount;
		ApplyRewards();
		Save();
	}

	public override void ApplyRewards()
	{
	}

	public override bool HasCompletedStage(int stageIndex)
	{
		if (stageIndex >= eligibleItems.Count)
		{
			return false;
		}
		StoreItemsConfig.StoreItem storeItem = StoreItemsConfig.instance.FindItemWithId(eligibleItems[stageIndex].itemId);
		return storeItem.IsOwned();
	}

	public override string GetStageText(int stageIndex)
	{
		if (stageIndex >= eligibleItems.Count)
		{
			return string.Empty;
		}
		StoreItemsConfig.StoreItem storeItem = StoreItemsConfig.instance.FindItemWithId(eligibleItems[stageIndex].itemId);
		return storeItem.name.ToString();
	}

	public override void UpdateAchievement(GGStoryAchivementsController.UpdateAchievementParams updateParams)
	{
		if (shouldShowAchievementStageCompleted)
		{
			achivementController.AchievementAccomplishedNotify(this);
		}
	}
}
